<template>
    <div>
       <el-table :data="this.tableData" ref="table" stripe>
        <tr v-for="(item, index) in this.tableLabel" :key="index">
            <el-table-column v-if="item.type==='checkbox'" :fixed="item.type==='checkbox'?'left':'none'" type="selection" width="55" :reserve-selection="true"></el-table-column>
            <el-table-column v-else-if="item.type==='createTime'" :prop="item.prop" :label="item.label" :min-width="item.width" :formatter="formatDate">
            </el-table-column>
            <el-table-column v-else-if="item.type==='updateTime'" :prop="item.prop" :label="item.label" :min-width="item.width" :formatter="formatDate">
            </el-table-column>
            <el-table-column v-else-if="item.type==='openTime'" :prop="item.prop" :label="item.label" :min-width="item.width" :formatter="formatTime">
            </el-table-column>
            <el-table-column v-else-if="item.type==='status'" :prop="item.prop" :label="item.label" :min-width="item.width">
                <template slot-scope="scope">
                    <template v-if="scope.row.status === '0'">
                      <el-tag type="warning">未签</el-tag>
                    </template>
                    <template v-else>
                      <el-tag type="success">已签</el-tag>
                    </template>
                  </template>
            </el-table-column>
            <el-table-column v-else-if="item.type==='normal'" :prop="item.prop" :label="item.label" :min-width="item.width"></el-table-column>
        </tr>
          <el-table-column label="操作" :fixed="this.models.fixed" :width="this.models.width">
              <template slot-scope="scope">
                  <el-button type="primary" v-if="scope.row.find" size="mini" @click="find(scope.row)">查看</el-button>
                  <template v-if="scope.row.status === '1'">
                     <el-button type="danger" v-if="scope.row.editPrice" size="mini" @click="edit(scope.row)">修改付款</el-button>
                  </template>
                  <el-button type="primary" v-if="scope.row.add" size="mini" @click="addContract(scope.row)">生成合同</el-button>
              </template>
          </el-table-column>
        </el-table>
        <el-row>
          <el-pagination
            class="page-footer"
            background
            layout="total,prev,pager,next,sizes,jumper"
            :total="this.models.total"
            :page-sizes="[10,20,30,40,50]"
            @current-change="handlePageChange"
            @size-change="handleSizeChange"
          />
        </el-row>
    </div>
  </template>
  
  <script>
import moment from 'moment'
  export default {
      props: {
          tableData: {
            type: Array,
            default: () => {
                return [];
            }
          },
          tableLabel:{
            type: Array,
            default: () => {
                return [];
            }
          },
          models: {
            type: Object,
            default: () => {
                return null;
            }
          },
      },
      data() {
          return {
               params: {
                  type:"page",
                  pageNum: 1,
                  pageSize: 10
              },
          };
      },
      mounted(){
         
      },
      methods: {
        formatDate(row, column) {
            const date = row[column.property]
            if (date == undefined) {
            return ''
            }
            return moment(date).format("YYYY-MM-DD")
        },
        formatTime(row, column) {
            const date = row[column.property]
            if (date == undefined) {
            return ''
            }
            return moment(date).format("YYYY-MM-DD HH:mm:ss")
        },
        find(row){
              this.$emit("on-find-click",row);
          },
          edit(row){
              this.$emit("on-edit-click",row);
          },
          addContract(row){
              this.$emit("on-addContract-click",row);
          },
          handlePageChange(page) {
             this.params.pageNum = page;
              this.loadList();
          },
          handleSizeChange(page) {
              this.params.pageSize = page;
              this.loadList();
          },
          loadList() {
              this.$emit("on-search-click", this.params);
          },
          onClose() {
              this.$emit("on-cancel");
          }
      }
  };
  </script>
  
  